package com.gongj.rabbitboot.rabbitmq.producer;

import com.alibaba.fastjson.JSON;
import com.gongj.rabbitboot.dto.PayDTO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.MessageDeliveryMode;
import org.springframework.amqp.core.MessagePostProcessor;
import org.springframework.amqp.core.MessageProperties;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

@Component
@Slf4j
public class RabbitSender {


    @Autowired
    private RabbitTemplate rabbitTemplate;

    public void send(PayDTO pay){
        log.info("支付发送消息 RabbitSender.send() payDTO = {}", JSON.toJSONString(pay));
//        MessagePostProcessor messagePostProcessor = message -> {
//        MessageProperties messageProperties = message.getMessageProperties();
//            //设置信息过期时间
//            messageProperties.setExpiration("10000");
//            return message;
//        };
        //发送hello world模型的方式消息
        rabbitTemplate.convertAndSend("hello-boot",pay);
    }

}
